﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TrackingAssist.WebTrends
{
    public class LocationFilter:IFilter
    {
        public IList<string> GetDataSource()
        {
            if (WebTrendsView.WebTrendsSpecList != null && WebTrendsView.WebTrendsSpecList.Count > 0)
            {
                IList<string> locationList = new List<string>();

                foreach (WebTrends webtrends in WebTrendsView.WebTrendsSpecList)
                {
                    if (webtrends.Location != null && !webtrends.Location.Value.StartsWith("[") && !webtrends.Location.Value.Equals(string.Empty) && !locationList.Contains(webtrends.Location.Value))
                    {
                        locationList.Add(webtrends.Location.Value);
                    }
                }

                return locationList;
            }
            return null;
        }


        public IList<WebTrends> GetFiltedSpecItems(IList<string> selectedItem)
        {
            if (selectedItem != null && selectedItem.Count > 0)
            {
                IList<WebTrends> specList = new List<WebTrends>();

                foreach (var item in selectedItem)
                {
                    foreach (WebTrends webtrends in WebTrendsView.WebTrendsSpecList)
                    {
                        if (string.Equals(webtrends.Location.Value, item))
                            specList.Add(webtrends);
                    }
                }
                return specList;
            }

            return null;
        }
    }
}
